/// 错误码常量
/// 
/// 与后端保持一致的错误码体系
/// 参考：企业级 Token 过期和失效设计方案.md
class ErrorCode {
  // ============ 认证授权 10xxx ============
  
  /// Token已过期
  static const int tokenExpired = 10001;
  
  /// Token无效
  static const int tokenInvalid = 10002;
  
  /// Token签名错误
  static const int tokenSignatureError = 10003;
  
  /// 权限不足
  static const int permissionDenied = 10010;
  
  /// 未登录
  static const int notLoggedIn = 10011;
  
  // ============ 业务错误 11xxx ============
  
  /// 通用业务错误
  static const int businessError = 11000;
  
  /// 参数错误
  static const int paramError = 11001;
  
  /// 数据不存在
  static const int dataNotFound = 11002;
  
  /// 数据重复
  static const int dataDuplicate = 11003;
  
  /// 操作失败
  static const int operationFailed = 11004;
  
  // ============ 系统错误 50xxx ============
  
  /// 系统错误
  static const int systemError = 50000;
  
  /// 空指针异常
  static const int nullPointer = 50001;
  
  /// 数据库错误
  static const int databaseError = 50002;
  
  /// 网络错误
  static const int networkError = 50003;
  
  // ============ 成功 ============
  
  /// 成功
  static const int success = 0;
  
  /// 获取错误码描述
  static String getDescription(int code) {
    switch (code) {
      case tokenExpired:
        return 'Token已过期';
      case tokenInvalid:
        return 'Token无效';
      case tokenSignatureError:
        return 'Token签名错误';
      case permissionDenied:
        return '权限不足';
      case notLoggedIn:
        return '未登录';
      case businessError:
        return '业务错误';
      case paramError:
        return '参数错误';
      case dataNotFound:
        return '数据不存在';
      case dataDuplicate:
        return '数据重复';
      case operationFailed:
        return '操作失败';
      case systemError:
        return '系统错误';
      case nullPointer:
        return '空指针异常';
      case databaseError:
        return '数据库错误';
      case networkError:
        return '网络错误';
      case success:
        return '成功';
      default:
        return '未知错误';
    }
  }
  
  /// 是否为Token相关错误
  static bool isTokenError(int code) {
    return code == tokenExpired || 
           code == tokenInvalid || 
           code == tokenSignatureError;
  }
  
  /// 是否为认证授权错误
  static bool isAuthError(int code) {
    return code >= 10000 && code < 11000;
  }
  
  /// 是否为业务错误
  static bool isBusinessError(int code) {
    return code >= 11000 && code < 50000;
  }
  
  /// 是否为系统错误
  static bool isSystemError(int code) {
    return code >= 50000;
  }
}

